import {KoaApplication} from "@atinc/chaos/application";
import {OperationContext} from "@atinc/chaos/router";
import {UserFacade} from "./moudles/user/facade";
import moment = require("moment");

export class App extends KoaApplication<OperationContext> {
    constructor(port: number, trace = true) {
        super({
            port: port,
            routerOptions: {
                prefix: "/api",
            },
            facades: [UserFacade],
            middlewares: [],
            accessLoggerOptions: {
                isEnable: true,
                label: "test"
            }

        }, async (ctx, next) => {
            if (trace) {
                const start = Date.now();
                await next();
                console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss.SSS")}] ${ctx.method} ${ctx.originalUrl}: ${Date.now() - start}ms`);
            } else {
                await next();
            }
        });
    }
}
